<?php
class My_Translate
{
	private static $translate;
	public static function setLanguage($lang)
	{
		$ssLang = new Zend_Session_Namespace("lang");
		$ssLang->lang = $lang;
	}
	
	public static function getLanguage()
	{
		$ssLang = new Zend_Session_Namespace("lang");
		if(!isset($ssLang->lang))
		{
			//default vietnam
			$ssLang->lang = 2;
		}
		return $ssLang->lang;
	}
	
	public static function getLanguageCode()
	{
		$lang = self::getLanguage();
		switch ($lang)
		{
			case 1:$langCode = "en";break;
			case 2:$langCode = "vn";break;
			default:$langCode = "vn";
		}
		return $langCode;
	}
	
	private static function getTranslator()
	{
		if(!isset(self::$translate))
		{
			$langCode = self::getLanguageCode();
			self::$translate = new Zend_Translate('ini',APPLICATION_PATH."/languages/lang_$langCode.ini", 'en');
			//self::$translate->addTranslation(APPLICATION_PATH.'/languages/lang_vn.ini', 'it');
		}
		return self::$translate;
	}
	public static function translate($msg)
	{
		$translate = self::getTranslator();
		return $translate->_($msg);
	}
}